<?php


namespace App\Admin\Actions\ProductBatch;


use App\Models\ProductsBatchLossModel;
use App\Models\ProductsBatchModel;
use App\Models\WarehouseAreaModel;
use App\Models\WarehouseModel;
use Encore\Admin\Actions\RowAction;
use Illuminate\Support\Facades\DB;

class AddArea extends RowAction
{
    public $name = '添加区域';

    public function handle(WarehouseModel $model, $data)
    {
        $area = new WarehouseAreaModel();
        $area['warehouse_id'] = $model['warehouse_id'];
        $area['area_name'] = $data['area_name'];
        $area['remark'] = $data['remark'];
        $area->save();

        return $area ? $this->response()->success('添加成功')->refresh() : $this->response()->error('添加失败');
    }

    public function form(WarehouseModel $model)
    {
        $this->text('area_name', '区域名称')->required();
        $this->textarea('remark', '备注')->placeholder('请输入1～255个字符');
    }
}
